package com.hera.process.config.dao;


import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.hera.base.dao.repository.BaseRepository;
import com.hera.process.form.domain.FormField;

public interface FormFieldDao extends BaseRepository<FormField, Long>{
	
	
	
	@Modifying
	@Transactional
	@Query("delete from FormField o where o.idProcess = ?")
	void deleteByProcess(Long idProcess);
	
	@Query("select o.field from DynaformField o where o.dynaformFieldPK.idDynaform = ?")
	List<FormField> findByDynaForm(Long idDynaform);
		
	List<FormField> findByIdProcess(Long idProcess);
	
	@Query("select dto.field from DynaformField dto where dto.dynaformFieldPK.idDynaform != ?1 and dto.dynaform.idProcess = ?2 "
			+ "and dto.dynaformFieldPK.idField not in (select dto2.field.idField from DynaformField dto2 where dto2.dynaformFieldPK.idDynaform = ?1) ")
	List<FormField> findFormFieldNoAsignado(Long idDynaform, Long idProcess);
	
	@Query("select distinct dto.field from DynaformField dto where dto.field.type.idParameterDetail != ?1 and dto.field.idProcess = ?2 "
			+ "and dto.dynaformFieldPK.idField not in (select dto2.field.idField from DynaformField dto2 where dto.field.type.idParameterDetail = ?1 and dto.field.idProcess = ?2) ")
	List<FormField> findAllFormFieldInProcess(Long idType, Long idProcess);
	
}
